﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using Axe.Extensions;
using System.Web.UI;
using System.ComponentModel;

namespace Axe.Web.Controls
{
    public class TimeSelector : CompositeControl, INamingContainer
    {
        MinutesList min = new MinutesList();
        HoursList hrs = new HoursList();

        public TimeSelector()
        {
            min.ID = "Minute";
            hrs.ID = "Hours";
        }

        [Bindable(true, BindingDirection.TwoWay)]
        public DateTime SelectedTime
        {
            get
            {
                int h, m;
                h = hrs.SelectedHour;
                m = min.SelectedMinute;

                DateTime now = DateTime.Today;
                now = now.AddMinutes(m);
                now = now.AddHours(h);
                return now;
            }
            set
            {
                hrs.SelectedHour = value.Hour;
                min.SelectedMinute = value.Minute;
            }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();
            Controls.Add(hrs);
            Controls.Add(new LiteralControl("&nbsp;"));
            Controls.Add(min);
            ChildControlsCreated = true;
            ClearChildViewState();
        }
    }
}
